function quickSort(arr, left = 0, right = arr.length - 1) {


    // 内部定义的函数
    function partition(arr, left, right) {
        const pivot = arr[right];
        let i = left - 1;

        for (let j = left; j < right; j++) {
            if (arr[j] <= pivot) {
                i++;
                [arr[i], arr[j]] = [arr[j], arr[i]];
            }
        }

        [arr[i + 1], arr[right]] = [arr[right], arr[i + 1]];

        return i + 1;
    }



    if (left < right) {
        const pivotIndex = partition(arr, left, right);
        quickSort(arr, left, pivotIndex - 1);
        quickSort(arr, pivotIndex + 1, right);
    }

    return arr;
}



// 示例数据
const unsortedArray = [5, 11, 2, 9, 1, 100, 8, 3, 7];

// 排序并输出结果
const sortedArray = quickSort(unsortedArray);
console.log(sortedArray);
